<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="theme-color" content="black"><meta name="author" content="李子康"><meta name="copyright" content="李子康"><meta name="generator" content="Hexo 4.2.1"><meta name="theme" content="hexo-theme-yun"><title>C#.net实现一个登录案例 | Lizikang_Blog</title><link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@900&amp;display=swap" media="none" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/star-markdown-css@0.1.11/dist/yun/yun-markdown.min.css"><script src="//at.alicdn.com/t/font_1140697_stqaphw3j4.js" async></script><script src="https://cdn.jsdelivr.net/npm/scrollreveal/dist/scrollreveal.min.js" defer></script><script>document.addEventListener("DOMContentLoaded", () => {
  [".post-card",".post-content img"].forEach((target)=> {
    ScrollReveal().reveal(target);
  })
});
</script><script src="https://cdn.jsdelivr.net/npm/pjax@latest/pjax.min.js" defer></script><script src="/js/pjax.js" defer></script><link rel="shortcut icon" type="image/svg+xml" href="/images/%E7%9A%AE%E5%8D%A1%E4%B8%98-2.ico"><link rel="mask-icon" href="/images/%E7%9A%AE%E5%8D%A1%E4%B8%98-2.ico" color="black"><link rel="alternate icon" href="/yun.ico"><link rel="preload" href="/css/hexo-theme-yun.css" as="style"><link rel="preload" href="/js/utils.js" as="script"><link rel="preload" href="/js/hexo-theme-yun.js" as="script"><link rel="prefetch" href="/js/sidebar.js" as="script"><link rel="preconnect" href="https://cdn.jsdelivr.net" crossorigin><link rel="stylesheet" href="/css/hexo-theme-yun.css"><link rel="alternate" href="/atom.xml" title="Lizikang_Blog"><script id="yun-config">
    const Yun = window.Yun || {};
    window.CONFIG = {"root":"/","title":["Li","Zi","Kang","Blog"],"version":"0.9.2","anonymous_image":"https://cdn.jsdelivr.net/gh/YunYouJun/cdn/img/avatar/none.jpg","say":{"api":"https://v1.hitokoto.cn","hitokoto":true},"fireworks":{"colors":["102, 167, 221","62, 131, 225","33, 78, 194"]}};
  </script><script src="//at.alicdn.com/t/font_1929835_1z6thct9lfe.js" async></script><meta name="description" content="C#.net实现一个登录案例1.Mysql数据库设计开启服务：  新建数据库、表：  插入数据：  2.VS2019 ASP.NET 环境安装https:&#x2F;&#x2F;blog.csdn.net&#x2F;qq_40401866&#x2F;article&#x2F;details&#x2F;104609155    安装成功后： 新建项目：  2.项目导入Mysql包：    3、项目设计 Login.aspx  1234567891011121">
<meta property="og:type" content="article">
<meta property="og:title" content="C#.net实现一个登录案例">
<meta property="og:url" content="http://yoursite.com/2021/05/26/%E4%BF%A1%E6%81%AF%E5%AE%89%E5%85%A8/%E4%BF%A1%E6%81%AF%E5%AE%89%E5%85%A8%E5%AE%9E%E7%8E%B0%E4%B8%80%E4%B8%AA%E7%99%BB%E5%BD%95%E6%A1%88%E4%BE%8B/index.html">
<meta property="og:site_name" content="Lizikang_Blog">
<meta property="og:description" content="C#.net实现一个登录案例1.Mysql数据库设计开启服务：  新建数据库、表：  插入数据：  2.VS2019 ASP.NET 环境安装https:&#x2F;&#x2F;blog.csdn.net&#x2F;qq_40401866&#x2F;article&#x2F;details&#x2F;104609155    安装成功后： 新建项目：  2.项目导入Mysql包：    3、项目设计 Login.aspx  1234567891011121">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210526141015250.png">
<meta property="og:image" content="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210526135004003.png">
<meta property="og:image" content="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210526135030902.png">
<meta property="og:image" content="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210526135420208.png">
<meta property="og:image" content="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210526135532262.png">
<meta property="og:image" content="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210525205447668.png">
<meta property="og:image" content="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210525210553981.png">
<meta property="og:image" content="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210525211328469.png">
<meta property="og:image" content="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210525211415162.png">
<meta property="og:image" content="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210525211424265.png">
<meta property="og:image" content="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210525211438297.png">
<meta property="og:image" content="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210526141143531.png">
<meta property="og:image" content="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210526140002057.png">
<meta property="og:image" content="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210526135104194.png">
<meta property="og:image" content="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210526135212778.png">
<meta property="og:image" content="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210526135253251.png">
<meta property="og:image" content="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210526135240595.png">
<meta property="og:image" content="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210526135129361.png">
<meta property="og:image" content="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210526134816022.png">
<meta property="og:image" content="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210526134846680.png">
<meta property="article:published_time" content="2021-05-25T16:00:00.000Z">
<meta property="article:modified_time" content="2021-05-26T06:39:00.942Z">
<meta property="article:author" content="李子康">
<meta property="article:tag" content="信息安全">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210526141015250.png"><script src="/js/ui/mode.js"></script><link rel="alternate" href="/atom.xml" title="Lizikang_Blog" type="application/atom+xml">
</head><body><script defer src="https://cdn.jsdelivr.net/npm/animejs@latest/anime.min.js"></script><script defer src="/js/ui/fireworks.js"></script><canvas class="fireworks"></canvas><div class="container"><a class="sidebar-toggle hty-icon-button" id="menu-btn"><div class="hamburger hamburger--spin" type="button"><span class="hamburger-box"><span class="hamburger-inner"></span></span></div></a><div class="sidebar-toggle sidebar-overlay"></div><aside class="sidebar"><script defer src="/js/sidebar.js"></script><ul class="sidebar-nav"><li class="sidebar-nav-item sidebar-nav-toc hty-icon-button sidebar-nav-active" data-target="post-toc-wrap" title="文章目录"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-list-ordered"></use></svg></li><li class="sidebar-nav-item sidebar-nav-overview hty-icon-button" data-target="site-overview-wrap" title="站点概览"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-passport-line"></use></svg></li></ul><div class="sidebar-panel" id="site-overview-wrap"><div class="site-info fix-top"><a class="site-author-avatar" href="/about/" title="李子康"><img width="96" loading="lazy" src="/images/bak.jpg" alt="李子康"></a><div class="site-author-name"><a href="/about/">李子康</a></div><a class="site-name" href="/about/site.html">Lizikang_Blog</a><sub class="site-subtitle"></sub><div class="site-desciption">个人技术博客</div></div><nav class="site-state"><a class="site-state-item hty-icon-button icon-home" href="/" title="我的主页"><span class="site-state-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-home-4-line"></use></svg></span></a><div class="site-state-item"><a href="/archives/" title="归档"><span class="site-state-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-archive-line"></use></svg></span><span class="site-state-item-count">27</span></a></div><div class="site-state-item"><a href="/categories/" title="分类"><span class="site-state-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-folder-2-line"></use></svg></span><span class="site-state-item-count">13</span></a></div><div class="site-state-item"><a href="/tags/" title="标签"><span class="site-state-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-price-tag-3-line"></use></svg></span><span class="site-state-item-count">9</span></a></div><a class="site-state-item hty-icon-button" href="https://yun.yunyoujun.cn" target="_blank" rel="noopener" title="文档"><span class="site-state-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-settings-line"></use></svg></span></a></nav><hr style="margin-bottom:0.5rem"><div class="links-of-author"><a class="links-of-author-item hty-icon-button" rel="noopener" href="https://wpa.qq.com/msgrd?v=3&amp;uin=1191787635&amp;site=qq&amp;menu=yes" title="QQ" target="_blank" style="color:#12B7F5"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-qq-line"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" href="https://github.com/lizikanglzk" title="GitHub" target="_blank" style="color:#181717"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-github-line"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" href="mailto:1191787635@qq.com" title="E-Mail" target="_blank" style="color:#8E71C1"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-mail-line"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" href="https://gitee.com/li_zikang" title="gitee" target="_blank" style="color:#E6162D"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-gitee-copy"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" href="https://music.163.com/#/user/home?id=506556053" title="网易云音乐" target="_blank" style="color:#C10D0C"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-netease-cloud-music-line"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" href="https://blog.csdn.net/qq_43845915" title="csdn" target="_blank" style="color:#007722"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-csdn11"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" href="https://www.zhihu.com/people/zou-guo-lu-guo-bu-yao-cuo-guo-88" title="知乎" target="_blank" style="color:#0084FF"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-zhihu-line"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" href="https://space.bilibili.com/352594163" title="哔哩哔哩动画" target="_blank" style="color:#FF8EB3"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-bilibili-line"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" title="微信" target="_blank" style="color:#1AAD19"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-wechat-2-line"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" href="/atom.xml" title="RSS" target="_blank" style="color:orange"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-rss-line"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" href="/game1" title="Telegram Channel" target="_blank" style="color:#0088CC"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-youxi-copy-copy"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" href="https://travellings.now.sh/" title="Travelling" target="_blank" style="color:var(--hty-text-color)"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-send-plane-2-line"></use></svg></a></div><hr style="margin:0.5rem 1rem"><div class="links"><a class="links-item hty-icon-button" href="/links/" title="我的小伙伴们" style="color:dodgerblue"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-men-line"></use></svg></a><a class="links-item hty-icon-button" href="/girls/" title="我的老婆们" style="color:#FF8EB3"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-women-line"></use></svg></a></div><br><a class="links-item hty-icon-button" id="toggle-mode-btn" href="javascript:;" title="Mode" style="color: #f1cb64"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-contrast-2-line"></use></svg></a></div><div class="sidebar-panel sidebar-panel-active" id="post-toc-wrap"><div class="post-toc"><div class="post-toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#C-net实现一个登录案例"><span class="toc-text">C#.net实现一个登录案例</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-Mysql数据库设计"><span class="toc-text">1.Mysql数据库设计</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-VS2019-ASP-NET-环境安装"><span class="toc-text">2.VS2019 ASP.NET 环境安装</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-项目导入Mysql包："><span class="toc-text">2.项目导入Mysql包：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3、项目设计"><span class="toc-text">3、项目设计</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#页面测试"><span class="toc-text">页面测试</span></a></li></ol></li></ol></div></div></div></aside><main class="sidebar-translate" id="content"><div id="post"><article class="post-block" itemscope itemtype="https://schema.org/Article"><link itemprop="mainEntityOfPage" href="http://yoursite.com/2021/05/26/%E4%BF%A1%E6%81%AF%E5%AE%89%E5%85%A8/%E4%BF%A1%E6%81%AF%E5%AE%89%E5%85%A8%E5%AE%9E%E7%8E%B0%E4%B8%80%E4%B8%AA%E7%99%BB%E5%BD%95%E6%A1%88%E4%BE%8B/"><span hidden itemprop="author" itemscope itemtype="https://schema.org/Person"><meta itemprop="name" content="李子康"><meta itemprop="description"></span><span hidden itemprop="publisher" itemscope itemtype="https://schema.org/Organization"><meta itemprop="name" content="Lizikang_Blog"></span><header class="post-header"><h1 class="post-title" itemprop="name headline">C#.net实现一个登录案例</h1><div class="post-meta"><div class="post-time" style="display:inline-block"><span class="post-meta-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-calendar-line"></use></svg></span> <time title="创建时间：2021-05-26 00:00:00" itemprop="dateCreated datePublished" datetime="2021-05-26T00:00:00+08:00">2021-05-26</time></div><span class="post-busuanzi"><span class="post-meta-divider">-</span><span class="post-meta-item-icon" title="阅读次数"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-eye-line"></use></svg> <span id="busuanzi_value_page_pv"></span></span></span><div class="post-classify"><span class="post-category"><span class="post-meta-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-folder-line"></use></svg></span> <span itemprop="about" itemscope itemtype="https://schema.org/Thing"><a class="category" href="/categories/%E4%BF%A1%E6%81%AF%E5%AE%89%E5%85%A8/" style="--text-color:var(--hty-text-color)" itemprop="url" rel="index"><span itemprop="text">信息安全</span></a></span></span><span class="post-tag"><span class="post-meta-divider">-</span><a class="tag" href="/tags/%E4%BF%A1%E6%81%AF%E5%AE%89%E5%85%A8/" style="--text-color:var(--hty-text-color)"><span class="post-meta-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-price-tag-3-line"></use></svg></span><span class="tag-name">信息安全</span></a></span></div></div></header><section class="post-body" itemprop="articleBody"><div class="post-content markdown-body" style="--smc-primary:black;"><h2 id="C-net实现一个登录案例"><a href="#C-net实现一个登录案例" class="headerlink" title="C#.net实现一个登录案例"></a>C#.net实现一个登录案例</h2><h3 id="1-Mysql数据库设计"><a href="#1-Mysql数据库设计" class="headerlink" title="1.Mysql数据库设计"></a>1.Mysql数据库设计</h3><p><strong>开启服务：</strong></p>
<p><img src="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210526141015250.png" alt="image-20210526141015250" loading="lazy"></p>
<p><strong>新建数据库、表：</strong></p>
<p><img src="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210526135004003.png" alt="image-20210526135004003" loading="lazy"></p>
<p><strong>插入数据：</strong></p>
<p><img src="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210526135030902.png" alt="image-20210526135030902" loading="lazy"></p>
<h3 id="2-VS2019-ASP-NET-环境安装"><a href="#2-VS2019-ASP-NET-环境安装" class="headerlink" title="2.VS2019 ASP.NET 环境安装"></a>2.VS2019 ASP.NET 环境安装</h3><p><a href="https://blog.csdn.net/qq_40401866/article/details/104609155" target="_blank" rel="noopener">https://blog.csdn.net/qq_40401866/article/details/104609155</a></p>
<p><img src="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210526135420208.png" alt="image-20210526135420208" loading="lazy"></p>
<p><img src="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210526135532262.png" alt="image-20210526135532262" loading="lazy"></p>
<p><img src="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210525205447668.png" alt="image-20210525205447668" loading="lazy"></p>
<p><strong>安装成功后：</strong></p>
<p>新建项目：</p>
<p><img src="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210525210553981.png" alt="image-20210525210553981" loading="lazy"></p>
<h3 id="2-项目导入Mysql包："><a href="#2-项目导入Mysql包：" class="headerlink" title="2.项目导入Mysql包："></a>2.项目导入Mysql包：</h3><p><img src="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210525211328469.png" alt="image-20210525211328469" loading="lazy"></p>
<p><img src="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210525211415162.png" alt="image-20210525211415162" loading="lazy"></p>
<p><img src="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210525211424265.png" alt="image-20210525211424265" loading="lazy"></p>
<p><img src="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210525211438297.png" alt="image-20210525211438297" loading="lazy"></p>
<h3 id="3、项目设计"><a href="#3、项目设计" class="headerlink" title="3、项目设计"></a>3、项目设计</h3><p><img src="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210526141143531.png" alt="image-20210526141143531" loading="lazy"></p>
<p>Login.aspx</p>
<p><img src="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210526140002057.png" alt="image-20210526140002057" loading="lazy"></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><code class="hljs C#">&lt;%@ Page Language&#x3D;&quot;C#&quot; AutoEventWireup&#x3D;&quot;true&quot; CodeBehind&#x3D;&quot;Login.aspx.cs&quot; Inherits&#x3D;&quot;Test01.Login&quot; %&gt;<br><br>&lt;!DOCTYPE html&gt;<br><br>&lt;html xmlns&#x3D;&quot;http:&#x2F;&#x2F;www.w3.org&#x2F;1999&#x2F;xhtml&quot;&gt;<br>&lt;head runat&#x3D;&quot;server&quot;&gt;<br>&lt;meta http-equiv&#x3D;&quot;Content-Type&quot; content&#x3D;&quot;text&#x2F;html; charset&#x3D;utf-8&quot;&#x2F;&gt;<br>    &lt;title&gt;&lt;&#x2F;title&gt;<br>&lt;&#x2F;head&gt;<br>&lt;body&gt;<br>    &lt;form id&#x3D;&quot;form1&quot; runat&#x3D;&quot;server&quot;&gt;<br>        &lt;div&gt;<br>        &lt;&#x2F;div&gt;<br>         用户名：&lt;asp:TextBox ID&#x3D;&quot;txtUserName&quot; runat&#x3D;&quot;server&quot;&gt;&lt;&#x2F;asp:TextBox&gt;<br>        &lt;br &#x2F;&gt;<br>        &lt;br &#x2F;&gt;<br>         密  码： &lt;asp:TextBox ID&#x3D;&quot;txtPwd&quot; runat&#x3D;&quot;server&quot;&gt;&lt;&#x2F;asp:TextBox&gt;<br>        &lt;br &#x2F;&gt;<br>        &lt;br &#x2F;&gt;<br>        &lt;asp:Button ID&#x3D;&quot;btnLogin&quot; runat&#x3D;&quot;server&quot; OnClick&#x3D;&quot;Button1_Click&quot; Text&#x3D;&quot;确定&quot; &#x2F;&gt;<br>       <br><br>    &lt;&#x2F;form&gt;<br>&lt;&#x2F;body&gt;<br>&lt;&#x2F;html&gt;<br></code></pre></td></tr></table></figure>

<p><strong>Login.aspx.cs</strong></p>
<p>对登录按钮写脚本：</p>
<blockquote>
<p> string connStr = “server=localhost;uid=root;pwd=123456;database=unity_test”;</p>
<p>localhost为ip地址，本地的话就写localhost</p>
<p>uid = 你的账号，</p>
<p>pwd= 你的密码</p>
<p>database= 你的数据库</p>
<p>（详细见上数据库） </p>
</blockquote>
<blockquote>
<p>string sql = “select count(*) from users where username=’”+name+”‘ and password=’”+pwd+”‘“;//获取数据中的信息</p>
<p>users 为你的表名</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br></pre></td><td class="code"><pre><code class="hljs c#">using MySql.Data.MySqlClient;<br>using System;<br>using System.Collections.Generic;<br>using System.Configuration;<br>using System.Data;<br>using System.Data.SqlClient;<br>using System.Linq;<br>using System.Web;<br>using System.Web.UI;<br>using System.Web.UI.WebControls;<br><br>namespace Test01<br>&#123;<br>    public partial class Login : System.Web.UI.Page<br>    &#123;<br>        <br>        protected void Page_Load(object sender, EventArgs e)<br>        &#123;<br><br>        &#125;<br><br>        protected void Button1_Click(object sender, EventArgs e)<br>        &#123;<br><br>            string name &#x3D; txtUserName.Text;<br>            string pwd &#x3D; txtPwd.Text;<br>            if (name !&#x3D; null || pwd !&#x3D; null)<br>            &#123;<br>                string sql &#x3D; &quot;select count(*) from users where username&#x3D;&#39;&quot;+name+&quot;&#39; and password&#x3D;&#39;&quot;+pwd+&quot;&#39;&quot;;&#x2F;&#x2F;获取数据中的信息<br>               <br>                &#x2F;&#x2F;连接数据库<br>                string connStr &#x3D; &quot;server&#x3D;localhost;uid&#x3D;root;pwd&#x3D;123456;database&#x3D;unity_test&quot;;<br>                MySqlConnection conn &#x3D; new MySqlConnection(connStr);<br>                conn.Open();<br>                MySqlCommand cmd &#x3D; new MySqlCommand(sql, conn);<br>                <br>                string obj &#x3D; cmd.ExecuteScalar().ToString();<br>                conn.Close();<br>                <br>                if (Convert.ToInt32(obj)&gt; 0)<br>                &#123;<br>                    &#x2F;&#x2F;Response.Write(&quot;登录成功&quot;);<br>                    Response.Write(&quot;&lt;script&gt;alert(&#39;登录成功！&#39;);&lt;&#x2F;script&gt;&quot;);<br>                &#125;<br>                else<br>                &#123;<br>                    &#x2F;&#x2F;Response.Write(&quot;登录失败&quot;);<br>                    Response.Write(&quot;&lt;script&gt;alert(&#39;用户名或密码错误，请重新输入！&#39;);&lt;&#x2F;script&gt;&quot;);<br>                &#125;<br>            &#125;<br>            else<br>            &#123;<br>                return;<br>            &#125;<br><br>        &#125;<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>



<h3 id="页面测试"><a href="#页面测试" class="headerlink" title="页面测试"></a>页面测试</h3><p><strong>登录成功：</strong></p>
<p><img src="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210526135104194.png" alt="image-20210526135104194" loading="lazy"></p>
<p><img src="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210526135212778.png" alt="image-20210526135212778" loading="lazy"></p>
<p><strong>登录失败：</strong></p>
<p><img src="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210526135253251.png" alt="image-20210526135253251" loading="lazy"></p>
<p><img src="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210526135240595.png" alt="image-20210526135240595" loading="lazy"></p>
<p><strong>sql 注入攻击</strong></p>
<blockquote>
<p>根据代码显示正常提交登录操作如用户名“admin”密码“123456”这样提交以后程序组合成的sql语句为“select * from users where username=’lzk’ and userpwd=’123456’”提交以后就应该显示登录成功对话框，然而用户非法输入密码的时候就有可能产生注入漏洞。比如用户名输入admin密码输入’or ‘1’=’1这是组合成的sql语句则为“select * from users where username=’admin’ and userpwd=’’ or ‘1’=’1’”这样就能通过验证因为有一个or把前面所有的判断都否定了只要or后面的成立就可以了。但是or后面还打了一个1=1这样不管or前面是什么后面这个1=1都成立这就导致判断始终成立。</p>
</blockquote>
<p><img src="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210526135129361.png" alt="image-20210526135129361" loading="lazy"></p>
<p><img src="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210526134816022.png" alt="image-20210526134816022" loading="lazy"></p>
<p><img src="https://gitee.com/li_zikang/lzk-image/raw/master/img/image-20210526134846680.png" alt="image-20210526134846680" loading="lazy"></p>
</div></section></article><div class="post-nav"><div class="post-nav-item"><a class="post-nav-prev" href="/2021/05/26/%E4%BF%A1%E6%81%AF%E5%AE%89%E5%85%A8/%E4%BF%A1%E6%81%AF%E5%AE%89%E5%85%A8%E5%AE%9E%E9%AA%8C4/" rel="prev" title="信息安全 实验四、web安全"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-arrow-left-s-line"></use></svg><span class="post-nav-text">信息安全 实验四、web安全</span></a></div><div class="post-nav-item"><a class="post-nav-next" href="/2021/05/21/%E4%BF%A1%E6%81%AF%E5%AE%89%E5%85%A8/%E4%BF%A1%E6%81%AF%E5%AE%89%E5%85%A8%E5%AE%9E%E9%AA%8C%E4%B8%89/" rel="next" title="信息安全实验三、网络监听"><span class="post-nav-text">信息安全实验三、网络监听</span><svg class="icon" aria-hidden="true"><use xlink:href="#icon-arrow-right-s-line"></use></svg></a></div></div></div><div id="comment"><div class="comment-tooltip text-center"></div><div id="valine-container"></div><script src="https://cdn.jsdelivr.net/npm/valine@latest/dist/Valine.min.js"></script><script>function initValine() {
  const valineConfig = {"enable":true,"appId":"q22e7srtjevOqYmzusWCYIru-gzGzoHsz","appKey":"PMyzTxHUFQ77nPj1IWMcMDK3","placeholder":"畅所欲言！","avatar":null,"meta":["nick","mail","link"],"pageSize":10,"visitor":false,"highlight":true,"recordIP":false,"enableQQ":true,"el":"#valine-container","lang":"zh-cn"}
  valineConfig.path = window.location.pathname
  new Valine(valineConfig)
}
setTimeout(initValine, 1000)</script></div></main><footer class="sidebar-translate" id="footer"><div class="copyright"><span>&copy; 2020 – 2022 </span><span class="with-love" id="animate"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-cloud-line"></use></svg></span><span class="author"> 李子康</span></div><div class="powered"><span>由 <a href="https://hexo.io" target="_blank" rel="noopener">Hexo</a> 驱动 v4.2.1</span><span class="footer-separator">|</span><span>主题 - <a rel="noopener" href="https://github.com/YunYouJun/hexo-theme-yun" target="_blank"><span>Yun</span></a> v0.9.2</span></div><div class="live_time"><span>本博客已萌萌哒地运行</span><span id="display_live_time"></span><span class="moe-text">(●'◡'●)</span><script>function blog_live_time() {
  window.setTimeout(blog_live_time, 1000);
  const start = new Date('2020-07-05T00:00:00');
  const now = new Date();
  const timeDiff = (now.getTime() - start.getTime());
  const msPerMinute = 60 * 1000;
  const msPerHour = 60 * msPerMinute;
  const msPerDay = 24 * msPerHour;
  const passDay = Math.floor(timeDiff / msPerDay);
  const passHour = Math.floor((timeDiff % msPerDay) / 60 / 60 / 1000);
  const passMinute = Math.floor((timeDiff % msPerHour) / 60 / 1000);
  const passSecond = Math.floor((timeDiff % msPerMinute) / 1000);
  display_live_time.innerHTML = " " + passDay + " 天 " + passHour + " 小时 " + passMinute + " 分 " + passSecond + " 秒";
}
blog_live_time();
</script></div><div id="busuanzi"><script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><span id="busuanzi_container_site_uv" title="总访客量"><span><svg class="icon" aria-hidden="true"><use xlink:href="#icon-user-line"></use></svg></span><span id="busuanzi_value_site_uv"></span></span><span class="footer-separator">|</span><span id="busuanzi_container_site_pv" title="总访问量"><span><svg class="icon" aria-hidden="true"><use xlink:href="#icon-eye-line"></use></svg></span><span id="busuanzi_value_site_pv"></span></span></div></footer><a class="hty-icon-button" id="goUp" aria-label="back-to-top" href="#"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-arrow-up-s-line"></use></svg><svg class="progress-circle-container" viewBox="0 0 100 100"><circle class="progress-circle" id="progressCircle" cx="50" cy="50" r="48" fill="none" stroke="black" stroke-width="2" stroke-linecap="round"></circle></svg></a></div><script defer src="/js/utils.js"></script><script defer src="/js/hexo-theme-yun.js"></script><script defer src="/js/player.js"></script></body></html>